package com.admin.oauth.component;

import com.admin.common.constant.Constant;
import com.admin.oauth.util.LoginUserUtil;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.Set;

/**
 * @author sq-lan
 */
@Service(value = "ss")
public class AuthorityComponent {

    public Boolean check(String... permissions) {
        Set<String> myPermissions = LoginUserUtil.permissions();
        // 判断用户拥有权限是否包含接口上定义的权限
        return myPermissions.contains(Constant.ADMIN) || Arrays.stream(permissions).anyMatch(myPermissions::contains);
    }
}
